/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tools;

/**
 *
 * @author ryulong
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import oracle.jdbc.OracleDriver;
import oracle.jdbc.pool.OracleDataSource;


public class koneksi {

    private static String jdbcUrl = "jdbc:oracle:thin:@172.23.9.185:1521:orcl";
    private static String userid = "MHS105314113";
    private static String password = "MHS105314113";
    private static Connection koneksi ;
//
//    private static String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:xe";
//    private static String userid = "hr";
//    private static String password = "afterglow";
//    private static Connection koneksi ;

//    ResultSet rset;
//    String query;
//    String sqlString;

   
   public static Connection KoneksiDB() throws SQLException {

       if(koneksi == null ) {
           DriverManager.registerDriver(new OracleDriver());
           koneksi = DriverManager.getConnection(jdbcUrl, userid, password);
           System.out.println("koneksi berhasil");
       }
       return koneksi;
   }
    public Connection  getDBConnection() {
        try {
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            koneksi = ds.getConnection(userid, password);
            System.out.println("Koneksi berhasil");

        } catch (SQLException ex) {
            System.out.println("Masih belum koneksi");
        }
        return koneksi;
    }

     public static void main(String[] args) {
       koneksi k = new koneksi();
        k.getDBConnection();
    }
}
